
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>3.2019-12-28-脚本MYSQL导出数据到PG · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="脚本MYSQL导出数据到PG">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="2020-01-04-docker-PostgreSQL安装文档.html" />
    
    
    <link rel="prev" href="2019-12-28-Postgres学习笔记.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="2.1" >
            
                <span>
            
                    
                    [bigdata]
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1.1" data-path="../bigdata/2019-12-30-spark-in-docker.html">
            
                <a href="../bigdata/2019-12-30-spark-in-docker.html">
            
                    
                    1.2019-12-30-spark-in-docker
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.2" data-path="../bigdata/2019-12-30-spark-RDD.html">
            
                <a href="../bigdata/2019-12-30-spark-RDD.html">
            
                    
                    2.2019-12-30-spark-RDD
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.3" data-path="../bigdata/2019-12-31-hadoop-hdfs命令别名.html">
            
                <a href="../bigdata/2019-12-31-hadoop-hdfs命令别名.html">
            
                    
                    3.2019-12-31-hadoop-hdfs命令别名
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.2" >
            
                <span>
            
                    
                    [c]
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.2.1" data-path="../c/2020-01-07-c语言.html">
            
                <a href="../c/2020-01-07-c语言.html">
            
                    
                    1.2020-01-07-c语言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.2" data-path="../c/2020-01-07-C语言基础教程.html">
            
                <a href="../c/2020-01-07-C语言基础教程.html">
            
                    
                    2.2020-01-07-C语言基础教程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.3" data-path="../c/2020-01-09-c语言语法基础.html">
            
                <a href="../c/2020-01-09-c语言语法基础.html">
            
                    
                    3.2020-01-09-c语言语法基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.3" >
            
                <span>
            
                    
                    [DataStructureandAlgorithms]
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.3.1" data-path="../DataStructureandAlgorithms/2019-12-28-数据结构和算法的关系.html">
            
                <a href="../DataStructureandAlgorithms/2019-12-28-数据结构和算法的关系.html">
            
                    
                    1.2019-12-28-数据结构和算法的关系
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.2" data-path="../DataStructureandAlgorithms/2019-12-28-稀疏数组.html">
            
                <a href="../DataStructureandAlgorithms/2019-12-28-稀疏数组.html">
            
                    
                    2.2019-12-28-稀疏数组
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.4" >
            
                <span>
            
                    
                    [git]
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.4.1" data-path="../git/2019-12-28-git-alias.html">
            
                <a href="../git/2019-12-28-git-alias.html">
            
                    
                    1.2019-12-28-git-alias
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.2" data-path="../git/2019-12-29-git常用命令.html">
            
                <a href="../git/2019-12-29-git常用命令.html">
            
                    
                    2.2019-12-29-git常用命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.3" data-path="../git/2019-12-31-git教程.html">
            
                <a href="../git/2019-12-31-git教程.html">
            
                    
                    3.2019-12-31-git教程
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.5" >
            
                <span>
            
                    
                    [go]
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.5.1" data-path="../go/2019-12-30-beego基本使用.html">
            
                <a href="../go/2019-12-30-beego基本使用.html">
            
                    
                    1.2019-12-30-beego基本使用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.6" >
            
                <span>
            
                    
                    [java]
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.6.1" data-path="../java/2019-12-30-环境变量和系统属性.html">
            
                <a href="../java/2019-12-30-环境变量和系统属性.html">
            
                    
                    1.2019-12-30-环境变量和系统属性
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.2" data-path="../java/2019-12-31-cloud-native-云原生.html">
            
                <a href="../java/2019-12-31-cloud-native-云原生.html">
            
                    
                    2.2019-12-31-cloud-native-云原生
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.3" data-path="../java/2019-12-31-java语法难点.html">
            
                <a href="../java/2019-12-31-java语法难点.html">
            
                    
                    3.2019-12-31-java语法难点
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.4" data-path="../java/2019-12-31-设计模式.html">
            
                <a href="../java/2019-12-31-设计模式.html">
            
                    
                    4.2019-12-31-设计模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.5" data-path="../java/2020-01-12-Ajax跨域问题解决方案.html">
            
                <a href="../java/2020-01-12-Ajax跨域问题解决方案.html">
            
                    
                    5.2020-01-12-Ajax跨域问题解决方案
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.6" data-path="../java/2020-01-12-freemarker应用场景介绍.html">
            
                <a href="../java/2020-01-12-freemarker应用场景介绍.html">
            
                    
                    6.2020-01-12-freemarker应用场景介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.7" data-path="../java/2020-01-12-jsp运行原理和运行过程.html">
            
                <a href="../java/2020-01-12-jsp运行原理和运行过程.html">
            
                    
                    7.2020-01-12-jsp运行原理和运行过程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.8" data-path="../java/2020-01-12-深入理解Maven中的Profile.html">
            
                <a href="../java/2020-01-12-深入理解Maven中的Profile.html">
            
                    
                    8.2020-01-12-深入理解Maven中的Profile
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.9" data-path="../java/2020-01-12-缓存穿透-缓存击穿-缓存雪崩概念及解决方案.html">
            
                <a href="../java/2020-01-12-缓存穿透-缓存击穿-缓存雪崩概念及解决方案.html">
            
                    
                    9.2020-01-12-缓存穿透-缓存击穿-缓存雪崩概念及解决方案
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.10" data-path="../java/2020-01-13-事务笔记.html">
            
                <a href="../java/2020-01-13-事务笔记.html">
            
                    
                    10.2020-01-13-事务笔记
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.11" data-path="../java/2020-01-13-幂等性.html">
            
                <a href="../java/2020-01-13-幂等性.html">
            
                    
                    11.2020-01-13-幂等性
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.12" data-path="../java/2020-01-16-java基本语法.html">
            
                <a href="../java/2020-01-16-java基本语法.html">
            
                    
                    12.2020-01-16-java基本语法
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.7" >
            
                <span>
            
                    
                    [arthas]
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.7.1" data-path="../java/arthas/2019-12-28-arthas-example.html">
            
                <a href="../java/arthas/2019-12-28-arthas-example.html">
            
                    
                    1.2019-12-28-arthas-example
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7.2" data-path="../java/arthas/2019-12-28-arthas添加支持执行历史命令的shell功能.html">
            
                <a href="../java/arthas/2019-12-28-arthas添加支持执行历史命令的shell功能.html">
            
                    
                    2.2019-12-28-arthas添加支持执行历史命令的shell功能
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7.3" data-path="../java/arthas/2020-01-10-思考性能调优.html">
            
                <a href="../java/arthas/2020-01-10-思考性能调优.html">
            
                    
                    3.2020-01-10-思考性能调优
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7.4" data-path="../java/arthas/2020-01-10-性能调优举例-最佳实践.html">
            
                <a href="../java/arthas/2020-01-10-性能调优举例-最佳实践.html">
            
                    
                    4.2020-01-10-性能调优举例-最佳实践
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7.5" data-path="../java/arthas/2020-01-10-性能调优举例一.html">
            
                <a href="../java/arthas/2020-01-10-性能调优举例一.html">
            
                    
                    5.2020-01-10-性能调优举例一
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7.6" data-path="../java/arthas/2020-01-10-性能调优举例三.html">
            
                <a href="../java/arthas/2020-01-10-性能调优举例三.html">
            
                    
                    6.2020-01-10-性能调优举例三
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7.7" data-path="../java/arthas/2020-01-10-性能调优举例二.html">
            
                <a href="../java/arthas/2020-01-10-性能调优举例二.html">
            
                    
                    7.2020-01-10-性能调优举例二
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7.8" data-path="../java/arthas/2020-01-10-性能调优举例四.html">
            
                <a href="../java/arthas/2020-01-10-性能调优举例四.html">
            
                    
                    8.2020-01-10-性能调优举例四
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7.9" data-path="../java/arthas/2020-01-15-性能调优举例五.html">
            
                <a href="../java/arthas/2020-01-15-性能调优举例五.html">
            
                    
                    9.2020-01-15-性能调优举例五
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7.10" data-path="../java/arthas/2020-05-12-性能调优举例六.html">
            
                <a href="../java/arthas/2020-05-12-性能调优举例六.html">
            
                    
                    10.2020-05-12-性能调优举例六
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7.11" data-path="../java/arthas/arthas-mind-map.html">
            
                <a href="../java/arthas/arthas-mind-map.html">
            
                    
                    11.arthas-mind-map
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.8" >
            
                <span>
            
                    
                    [dubbo]
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.8.1" data-path="../java/dubbo/2019-12-28-dubbo涉及的技术.html">
            
                <a href="../java/dubbo/2019-12-28-dubbo涉及的技术.html">
            
                    
                    1.2019-12-28-dubbo涉及的技术
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.8.2" data-path="../java/dubbo/2019-12-30-dubbo消费者访问流程.html">
            
                <a href="../java/dubbo/2019-12-30-dubbo消费者访问流程.html">
            
                    
                    2.2019-12-30-dubbo消费者访问流程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.8.3" data-path="../java/dubbo/2019-12-30-dubbo面试.html">
            
                <a href="../java/dubbo/2019-12-30-dubbo面试.html">
            
                    
                    3.2019-12-30-dubbo面试
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.9" >
            
                <span>
            
                    
                    [jdk]
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.9.1" data-path="../java/jdk/2020-01-12-实例介绍 JAVA 泛型基础.html">
            
                <a href="../java/jdk/2020-01-12-实例介绍 JAVA 泛型基础.html">
            
                    
                    1.2020-01-12-实例介绍 JAVA 泛型基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.9.2" data-path="../java/jdk/2020-01-13-ThreadLocal六连问.html">
            
                <a href="../java/jdk/2020-01-13-ThreadLocal六连问.html">
            
                    
                    2.2020-01-13-ThreadLocal六连问
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.10" >
            
                <span>
            
                    
                    [jvm]
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.10.1" data-path="../java/jvm/2019-12-30-性能调优.html">
            
                <a href="../java/jvm/2019-12-30-性能调优.html">
            
                    
                    1.2019-12-30-性能调优
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.11" >
            
                <span>
            
                    
                    [netty]
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.11.1" data-path="../java/netty/2020-01-16-netty入门.html">
            
                <a href="../java/netty/2020-01-16-netty入门.html">
            
                    
                    1.2020-01-16-netty入门
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.11.2" data-path="../java/netty/2020-01-16-netty核心概念.html">
            
                <a href="../java/netty/2020-01-16-netty核心概念.html">
            
                    
                    2.2020-01-16-netty核心概念
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.12" >
            
                <span>
            
                    
                    [solr]
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.12.1" data-path="../java/solr/2019-12-28-solr-7.6.0.tgz安装.html">
            
                <a href="../java/solr/2019-12-28-solr-7.6.0.tgz安装.html">
            
                    
                    1.2019-12-28-solr-7.6.0.tgz安装
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.13" >
            
                <span>
            
                    
                    [spring]
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.13.1" data-path="../java/spring/2020-01-12-SpringBoot属性读取方式介绍.html">
            
                <a href="../java/spring/2020-01-12-SpringBoot属性读取方式介绍.html">
            
                    
                    1.2020-01-12-SpringBoot属性读取方式介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.13.2" data-path="../java/spring/2020-01-12-使用spring boot+mybatis plus快速入门.html">
            
                <a href="../java/spring/2020-01-12-使用spring boot+mybatis plus快速入门.html">
            
                    
                    2.2020-01-12-使用spring boot+mybatis plus快速入门
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.13.3" data-path="../java/spring/2020-01-13-spring-initMethod-destoryMethod.html">
            
                <a href="../java/spring/2020-01-13-spring-initMethod-destoryMethod.html">
            
                    
                    3.2020-01-13-spring-initMethod-destoryMethod
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.13.4" data-path="../java/spring/2020-01-13-spring循环依赖.html">
            
                <a href="../java/spring/2020-01-13-spring循环依赖.html">
            
                    
                    4.2020-01-13-spring循环依赖
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.13.5" data-path="../java/spring/2020-01-13-spring源码随记.html">
            
                <a href="../java/spring/2020-01-13-spring源码随记.html">
            
                    
                    5.2020-01-13-spring源码随记
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.13.6" data-path="../java/spring/2020-01-13-自定义mini-spring.html">
            
                <a href="../java/spring/2020-01-13-自定义mini-spring.html">
            
                    
                    6.2020-01-13-自定义mini-spring
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.14" >
            
                <span>
            
                    
                    [websocket]
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.14.1" data-path="../java/websocket/2019-12-30-webscoket-springboot通信.html">
            
                <a href="../java/websocket/2019-12-30-webscoket-springboot通信.html">
            
                    
                    1.2019-12-30-webscoket-springboot通信
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.15" >
            
                <span>
            
                    
                    [linux]
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.15.1" data-path="../linux/2019-12-28-Linux常用命令和快捷键.html">
            
                <a href="../linux/2019-12-28-Linux常用命令和快捷键.html">
            
                    
                    1.2019-12-28-Linux常用命令和快捷键
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.15.2" data-path="../linux/2019-12-28-从零到一环境安装.html">
            
                <a href="../linux/2019-12-28-从零到一环境安装.html">
            
                    
                    2.2019-12-28-从零到一环境安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.15.3" data-path="../linux/2019-12-30-vi-常用命令.html">
            
                <a href="../linux/2019-12-30-vi-常用命令.html">
            
                    
                    3.2019-12-30-vi-常用命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.15.4" data-path="../linux/2019-12-31-awk命令.html">
            
                <a href="../linux/2019-12-31-awk命令.html">
            
                    
                    4.2019-12-31-awk命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.15.5" data-path="../linux/2019-12-31-cup信息分析.html">
            
                <a href="../linux/2019-12-31-cup信息分析.html">
            
                    
                    5.2019-12-31-cup信息分析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.15.6" data-path="../linux/2019-12-31-shell编程.html">
            
                <a href="../linux/2019-12-31-shell编程.html">
            
                    
                    6.2019-12-31-shell编程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.15.7" data-path="../linux/2019-12-31-top命令.html">
            
                <a href="../linux/2019-12-31-top命令.html">
            
                    
                    7.2019-12-31-top命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.15.8" data-path="../linux/2019-12-31-普通用户docker的问题.html">
            
                <a href="../linux/2019-12-31-普通用户docker的问题.html">
            
                    
                    8.2019-12-31-普通用户docker的问题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.15.9" data-path="../linux/2020-01-01-centos7 安装kubernetes.html">
            
                <a href="../linux/2020-01-01-centos7 安装kubernetes.html">
            
                    
                    9.2020-01-01-centos7 安装kubernetes
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.15.10" data-path="../linux/2020-01-01-centos安装常用配置.html">
            
                <a href="../linux/2020-01-01-centos安装常用配置.html">
            
                    
                    10.2020-01-01-centos安装常用配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.15.11" data-path="../linux/2020-01-01-docker使用.html">
            
                <a href="../linux/2020-01-01-docker使用.html">
            
                    
                    11.2020-01-01-docker使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.15.12" data-path="../linux/2020-01-01-kubernetes使用.html">
            
                <a href="../linux/2020-01-01-kubernetes使用.html">
            
                    
                    12.2020-01-01-kubernetes使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.15.13" data-path="../linux/2020-05-12-PG有用的SQL.html">
            
                <a href="../linux/2020-05-12-PG有用的SQL.html">
            
                    
                    13.2020-05-12-PG有用的SQL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.15.14" data-path="../linux/2020-05-12-vim命令.html">
            
                <a href="../linux/2020-05-12-vim命令.html">
            
                    
                    14.2020-05-12-vim命令
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.16" >
            
                <span>
            
                    
                    [automate]
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.16.1" data-path="../linux/automate/2020-01-12-redis伪集群创建脚本.html">
            
                <a href="../linux/automate/2020-01-12-redis伪集群创建脚本.html">
            
                    
                    1.2020-01-12-redis伪集群创建脚本
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.16.2" data-path="../linux/automate/2020-01-12-tomcat集群创建脚本.html">
            
                <a href="../linux/automate/2020-01-12-tomcat集群创建脚本.html">
            
                    
                    2.2020-01-12-tomcat集群创建脚本
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.16.3" data-path="../linux/automate/2020-01-12-zookeeper自动化脚本.html">
            
                <a href="../linux/automate/2020-01-12-zookeeper自动化脚本.html">
            
                    
                    3.2020-01-12-zookeeper自动化脚本
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.16.4" data-path="../linux/automate/2020-01-12-其他自动化脚本.html">
            
                <a href="../linux/automate/2020-01-12-其他自动化脚本.html">
            
                    
                    4.2020-01-12-其他自动化脚本
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.17" >
            
                <span>
            
                    
                    [MySQL]
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.17.1" data-path="../MySQL/2019-12-31-mysql常用命令.html">
            
                <a href="../MySQL/2019-12-31-mysql常用命令.html">
            
                    
                    1.2019-12-31-mysql常用命令
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.18" >
            
                <span>
            
                    
                    [nginx]
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.18.1" data-path="../nginx/2019-12-29-Nginx-Keepalived高可用集群.html">
            
                <a href="../nginx/2019-12-29-Nginx-Keepalived高可用集群.html">
            
                    
                    1.2019-12-29-Nginx-Keepalived高可用集群
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.18.2" data-path="../nginx/2020-01-16-nginx参数详细说明.html">
            
                <a href="../nginx/2020-01-16-nginx参数详细说明.html">
            
                    
                    2.2020-01-16-nginx参数详细说明
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.19" >
            
                <span>
            
                    
                    [other]
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.19.1" data-path="../other/2019-12-28-知识小计.html">
            
                <a href="../other/2019-12-28-知识小计.html">
            
                    
                    1.2019-12-28-知识小计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.19.2" data-path="../other/2020-01-04-科学上网.html">
            
                <a href="../other/2020-01-04-科学上网.html">
            
                    
                    2.2020-01-04-科学上网
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.19.3" data-path="../other/2020-05-13-正则表达式.html">
            
                <a href="../other/2020-05-13-正则表达式.html">
            
                    
                    3.2020-05-13-正则表达式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.19.4" data-path="../other/template.html">
            
                <a href="../other/template.html">
            
                    
                    4.template
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.20" >
            
                <span>
            
                    
                    [PostgreSQL]
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.20.1" data-path="2019-12-28-PostgreSQL安装文档.html">
            
                <a href="2019-12-28-PostgreSQL安装文档.html">
            
                    
                    1.2019-12-28-PostgreSQL安装文档
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.20.2" data-path="2019-12-28-Postgres学习笔记.html">
            
                <a href="2019-12-28-Postgres学习笔记.html">
            
                    
                    2.2019-12-28-Postgres学习笔记
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="2.20.3" data-path="2019-12-28-脚本MYSQL导出数据到PG.html">
            
                <a href="2019-12-28-脚本MYSQL导出数据到PG.html">
            
                    
                    3.2019-12-28-脚本MYSQL导出数据到PG
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.20.4" data-path="2020-01-04-docker-PostgreSQL安装文档.html">
            
                <a href="2020-01-04-docker-PostgreSQL安装文档.html">
            
                    
                    4.2020-01-04-docker-PostgreSQL安装文档
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.20.5" data-path="2020-01-17-阿里云PG主从切换问题.html">
            
                <a href="2020-01-17-阿里云PG主从切换问题.html">
            
                    
                    5.2020-01-17-阿里云PG主从切换问题
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.21" >
            
                <span>
            
                    
                    [python]
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.21.1" data-path="../python/2019-12-28-pip-install指定国内源镜像.html">
            
                <a href="../python/2019-12-28-pip-install指定国内源镜像.html">
            
                    
                    1.2019-12-28-pip-install指定国内源镜像
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.21.2" data-path="../python/2019-12-30-python内置函数.html">
            
                <a href="../python/2019-12-30-python内置函数.html">
            
                    
                    2.2019-12-30-python内置函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.21.3" data-path="../python/2019-12-30-一图搞懂基本python语法 .html">
            
                <a href="../python/2019-12-30-一图搞懂基本python语法 .html">
            
                    
                    3.2019-12-30-一图搞懂基本python语法 
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.22" >
            
                <span>
            
                    
                    [redis]
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.22.1" data-path="../redis/2019-12-28-redis5.0.3安装.html">
            
                <a href="../redis/2019-12-28-redis5.0.3安装.html">
            
                    
                    1.2019-12-28-redis5.0.3安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.22.2" data-path="../redis/2019-12-28-redis5.0.3集群搭建.html">
            
                <a href="../redis/2019-12-28-redis5.0.3集群搭建.html">
            
                    
                    2.2019-12-28-redis5.0.3集群搭建
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.23" >
            
                <span>
            
                    
                    [tool]
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.23.1" data-path="../tool/2019-12-28-idea高效使用技巧和快捷键.html">
            
                <a href="../tool/2019-12-28-idea高效使用技巧和快捷键.html">
            
                    
                    1.2019-12-28-idea高效使用技巧和快捷键
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.23.2" data-path="../tool/2019-12-28-PlantUML画图脚本.html">
            
                <a href="../tool/2019-12-28-PlantUML画图脚本.html">
            
                    
                    2.2019-12-28-PlantUML画图脚本
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.23.3" data-path="../tool/2019-12-30-vscode高效使用.html">
            
                <a href="../tool/2019-12-30-vscode高效使用.html">
            
                    
                    3.2019-12-30-vscode高效使用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.24" >
            
                <span>
            
                    
                    [windows]
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.24.1" data-path="../windows/2020-01-12-本地服务成为互联网服务.html">
            
                <a href="../windows/2020-01-12-本地服务成为互联网服务.html">
            
                    
                    1.2020-01-12-本地服务成为互联网服务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.24.2" data-path="../windows/2020-01-12-注册bat为windows服务.html">
            
                <a href="../windows/2020-01-12-注册bat为windows服务.html">
            
                    
                    2.2020-01-12-注册bat为windows服务
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >3.2019-12-28-脚本MYSQL导出数据到PG</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <p>&#x6700;&#x5F3A;&#x5927;&#x7684;&#x5F00;&#x6E90;&#x6570;&#x636E;&#x5E93;&#xFF0C;PG&#x5E72;O&#xFF0C;&#x5929;&#x5929;&apos;&#x8C61;&apos;&#x4E0A;</p>
<h2 id="&#x8FDE;&#x63A5;pg">&#x8FDE;&#x63A5;pg</h2>
<pre><code class="lang-shell"> psql &quot;dbname=test user=dbusername password=12345678&quot;
</code></pre>
<h2 id="pg&#x6A21;&#x5F0F;schema&#x8FC1;&#x79FB;">pg&#x6A21;&#x5F0F;schema&#x8FC1;&#x79FB;</h2>
<p>&#x76F8;&#x540C;&#x7C7B;&#x578B;&#x7684;&#x6570;&#x636E;&#x5E93;schema&#x8FC1;&#x79FB;&#x7B80;&#x4ECB;</p>
<pre><code class="lang-shell">&#x5BFC;&#x51FA;&#x6570;&#x636E;&#x5E93;music&#x4E2D;&#x7684;&#x6A21;&#x5F0F;gaoqiang&#x7684;&#x8868;&#x7ED3;&#x6784;&#x548C;&#x6570;&#x636E;&#xFF1A;
pg_dump -U user -d music -n gaoqiang -f /tmp/gaoqiang.sql

&#x6279;&#x91CF;&#x66FF;&#x6362;&#x5B57;&#x7B26;&#x4E32;
sed -i &quot;s/account001/account002/g&quot;  account002.sql
&#x6CE8;&#xFF1A;

-i &#x8868;&#x793A;inplace edit&#xFF0C;&#x5C31;&#x5730;&#x4FEE;&#x6539;&#x6587;&#x4EF6;

 -r &#x8868;&#x793A;&#x641C;&#x7D22;&#x5B50;&#x76EE;&#x5F55;

 -l &#x8868;&#x793A;&#x8F93;&#x51FA;&#x5339;&#x914D;&#x7684;&#x6587;&#x4EF6;&#x540D;
s&#x8868;&#x793A;&#x66FF;&#x6362;&#xFF0C;d&#x8868;&#x793A;&#x5220;&#x9664;

#&#x5BFC;&#x5165;&#x8868;&#x6570;&#x636E;
 psql -f account002.sql  &quot;dbname=v7pgbaseline user=jdy password=Jdy#2019&quot;
</code></pre>
<h2 id="mysqldump">mysqldump</h2>
<pre><code class="lang-shell">mysqldump&#x5BFC;&#x51FA;mysql&#x8868;&#x7ED3;&#x6784;
mysqldump --compatible=postgresql --default-character-set=utf8 -r dump_sql_file.mysql --add-drop-table -h ip_or_host   -u root --opt -d dbname  -p
--add-drop-table
Python&#x811A;&#x672C; &#x8F6C;&#x6362;mysql&#x8BED;&#x53E5;&#x9002;&#x914D;pg
python db_converter.py dump_sql_file.mysql dump_sql_file.psql

pg&#x5BFC;&#x5165;&#x8868;&#x7ED3;&#x6784;&#xFF0C;&#x5148;drop&#x8868;&#x518D;&#x521B;&#x5EFA;&#x8868;
psql -f dump_sql_file.pgsql &quot;dbname=cbtest user=dbusername password=dbpassword&quot; &#x5BFC;&#x5165;&#x8868;&#x7ED3;&#x6784;


mysqldump&#x5BFC;&#x51FA;&#x5168;&#x90E8;&#x6570;&#x636E;
mysqldump -t dump_sql_file --default-character-set=utf8  -u root -p &gt; mysqldata.sql

mysqldump&#x5BFC;&#x51FA;&#x8FDC;&#x7A0B;&#x6307;&#x5B9A;&#x8868;&#x6570;&#x636E;
mysqldump -t dump_sql_file --table one_table_name  --default-character-set=utf8 -h ip_or_host   -uroot -pdbpassword &gt; mysqldata.sql

&#x8F6C;&#x6362;
python db_converter.py mysqldata.sql pgdata.sql

pg&#x5BFC;&#x5165;
psql -f pgdata.sql &quot;dbname=cbtest user=dbusername password=dbpassword&quot;
</code></pre>
<h2 id="pg&#x5BFC;&#x51FA;">pg&#x5BFC;&#x51FA;</h2>
<pre><code class="lang-shell">&#x5BFC;&#x51FA;&#x4E00;&#x4E2A;&#x6570;&#x636E;&#x5E93;&#x4E2D;&#x4E00;&#x4E2A;&#x8868;&#x7684;&#x6570;&#x636E;
pg_dump -d dbname -t one_table_name --inserts -a -f one_table_name.sql -U dbusername

&#x5143;&#x6570;&#x636E;&#x8FC1;&#x79FB;&#x811A;&#x672C;
#&#x5BFC;&#x51FA;&#x9700;&#x8981;&#x7684;&#x8868;&#xFF0C;&#x4EE5; table_name &#x5F00;&#x5934;
psql -p 5432 -U dbusername -d dbname -c &quot;select tablename from pg_tables where tablename like &apos;table_name%&apos;;&quot; &gt; .testout

#&#x83B7;&#x53D6;&#x6587;&#x4EF6;&#x5185;&#x5BB9;&#x5FAA;&#x73AF;
cat .testout | while read line
do
#&#x8868;&#x9700;&#x8981;&#x4EE5; table_name &#x5F00;&#x5934;
if [[ $line == table_name* ]];
then
 echo $line
 #&#x5BFC;&#x51FA;&#x8868;&#x6570;&#x636E;
 pg_dump -d dbname -t $line --inserts -a -f ${line}.sql -U dbusername
 #&#x622A;&#x65AD;&#x8868;&#x6570;&#x636E;
 psql -p 5432 -U dbusername -d bos_mysql_to_pg -c &quot;TRUNCATE TABLE ${line};&quot;
 #&#x5BFC;&#x5165;&#x8868;&#x6570;&#x636E;
 psql -f ${line}.sql  &quot;dbname=db_mysql_to_pg user=dbusername password=dbpassword&quot;
 #&#x5220;&#x9664;&#x4E34;&#x65F6;&#x6587;&#x4EF6;
 rm -f ${line}.sql
fi

done
</code></pre>
<h2 id="&#x7D22;&#x5F15;&#x5904;&#x7406;">&#x7D22;&#x5F15;&#x5904;&#x7406;</h2>
<p>&#x6839;&#x636E;mysql&#x6570;&#x636E;&#x5E93;&#x751F;&#x6210;&#x5BF9;&#x5E94;pg&#x7684;&#x7D22;&#x5F15;&#x811A;&#x672C;
&#x5BFC;&#x51FA;&#x521B;&#x5EFA;&#x7D22;&#x5F15;&#x8BED;&#x53E5;
mysql -h ip_or_host -uroot -pdbpassword  -Ddump_sql_file &lt; getcreateindex.sql &gt; create_indexs.sql</p>
<h2 id="&#x5BFC;&#x5165;pg">&#x5BFC;&#x5165;pg</h2>
<pre><code class="lang-shell">psql -f create_indexs.sql   &quot;dbname=bos_mysql_to_pg user=dbusername password=dbpassword&quot;
</code></pre>
<p>&#x751F;&#x6210;&#x521B;&#x5EFA;&#x7D22;&#x5F15;&#x7684;SQL</p>
<pre><code class="lang-sql"><span class="hljs-comment">-- CREATE INDEX IDX_T_ANALYSIS_REPORT_DATE ON t_analysis_report USING btree (FBEGINDATE, FENDDATE);</span>
<span class="hljs-keyword">SELECT</span>
        <span class="hljs-keyword">IF</span> (
            NON_UNIQUE = <span class="hljs-number">1</span>,
            <span class="hljs-keyword">CASE</span> <span class="hljs-keyword">UPPER</span>(INDEX_TYPE)
        <span class="hljs-keyword">WHEN</span> <span class="hljs-string">&apos;FULLTEXT&apos;</span> <span class="hljs-keyword">THEN</span>
            <span class="hljs-string">&apos;FULLTEXT INDEX&apos;</span>
        <span class="hljs-keyword">WHEN</span> <span class="hljs-string">&apos;SPATIAL&apos;</span> <span class="hljs-keyword">THEN</span>
            <span class="hljs-string">&apos;SPATIAL INDEX&apos;</span>
        <span class="hljs-keyword">ELSE</span>
            <span class="hljs-keyword">CONCAT</span>(
                <span class="hljs-string">&apos;CREATE INDEX &apos;</span>,
                INDEX_NAME,
                <span class="hljs-string">&apos; &apos;</span>,
                <span class="hljs-string">&apos;ON &apos;</span>,
                <span class="hljs-string">&apos;&apos;</span>,
                TABLE_NAME,
                <span class="hljs-string">&apos; USING &apos;</span>,
                INDEX_TYPE,
                <span class="hljs-string">&apos;(&apos;</span>,
                <span class="hljs-keyword">GROUP_CONCAT</span>(
                    <span class="hljs-keyword">DISTINCT</span> <span class="hljs-keyword">CONCAT</span>(<span class="hljs-string">&apos;&apos;</span>, COLUMN_NAME, <span class="hljs-string">&apos;&apos;</span>)
                    <span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span>
                        SEQ_IN_INDEX <span class="hljs-keyword">ASC</span> SEPARATOR <span class="hljs-string">&apos;, &apos;</span>
                ),
                <span class="hljs-string">&apos;);&apos;</span>
            )
        <span class="hljs-keyword">END</span>,
        <span class="hljs-string">&apos;&apos;</span>
        )
     <span class="hljs-keyword">AS</span> <span class="hljs-string">&apos;Show_Add_Indexes&apos;</span>
<span class="hljs-keyword">FROM</span>
    information_schema.<span class="hljs-keyword">STATISTICS</span>
<span class="hljs-keyword">WHERE</span>
    TABLE_SCHEMA = <span class="hljs-string">&apos;dump_sql_file&apos;</span>
<span class="hljs-keyword">GROUP</span> <span class="hljs-keyword">BY</span>
    TABLE_NAME,
    INDEX_NAME
<span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span>
    TABLE_NAME <span class="hljs-keyword">ASC</span>,
    INDEX_NAME <span class="hljs-keyword">ASC</span>
</code></pre>
<p>&#x4FEE;&#x6539;&#x589E;&#x52A0;</p>
<pre><code class="lang-sql"><span class="hljs-keyword">alter</span> <span class="hljs-keyword">table</span> ...
<span class="hljs-keyword">SELECT</span>
    <span class="hljs-keyword">CONCAT</span>(
        <span class="hljs-string">&apos;ALTER TABLE &apos;</span>,
        TABLE_NAME,
        <span class="hljs-string">&apos; &apos;</span>,
        <span class="hljs-string">&apos;ADD &apos;</span>,

    <span class="hljs-keyword">IF</span> (
        NON_UNIQUE = <span class="hljs-number">1</span>,
        <span class="hljs-keyword">CASE</span> <span class="hljs-keyword">UPPER</span>(INDEX_TYPE)
    <span class="hljs-keyword">WHEN</span> <span class="hljs-string">&apos;FULLTEXT&apos;</span> <span class="hljs-keyword">THEN</span>
        <span class="hljs-string">&apos;FULLTEXT INDEX&apos;</span>
    <span class="hljs-keyword">WHEN</span> <span class="hljs-string">&apos;SPATIAL&apos;</span> <span class="hljs-keyword">THEN</span>
        <span class="hljs-string">&apos;SPATIAL INDEX&apos;</span>
    <span class="hljs-keyword">ELSE</span>
        <span class="hljs-keyword">CONCAT</span>(
            <span class="hljs-string">&apos;INDEX &apos;</span>,
            INDEX_NAME,
            <span class="hljs-string">&apos; USING &apos;</span>,
            INDEX_TYPE
        )
    <span class="hljs-keyword">END</span>,

<span class="hljs-keyword">IF</span> (
    <span class="hljs-keyword">UPPER</span>(INDEX_NAME) = <span class="hljs-string">&apos;PRIMARY&apos;</span>,
    <span class="hljs-keyword">CONCAT</span>(
        <span class="hljs-string">&apos;PRIMARY KEY USING &apos;</span>,
        INDEX_TYPE
    ),
    <span class="hljs-keyword">CONCAT</span>(
        <span class="hljs-string">&apos;UNIQUE INDEX &apos;</span>,
        INDEX_NAME,
        <span class="hljs-string">&apos; USING &apos;</span>,
        INDEX_TYPE
    )
)
    ),
    <span class="hljs-string">&apos;(&apos;</span>,
    <span class="hljs-keyword">GROUP_CONCAT</span>(
        <span class="hljs-keyword">DISTINCT</span> <span class="hljs-keyword">CONCAT</span>(<span class="hljs-string">&apos;&apos;</span>, COLUMN_NAME, <span class="hljs-string">&apos;&apos;</span>)
        <span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span>
            SEQ_IN_INDEX <span class="hljs-keyword">ASC</span> SEPARATOR <span class="hljs-string">&apos;, &apos;</span>
    ),
    <span class="hljs-string">&apos;);&apos;</span>
    ) <span class="hljs-keyword">AS</span> <span class="hljs-string">&apos;Show_Add_Indexes&apos;</span>
<span class="hljs-keyword">FROM</span>
    information_schema.<span class="hljs-keyword">STATISTICS</span>
<span class="hljs-keyword">WHERE</span>
    TABLE_SCHEMA = <span class="hljs-string">&apos;dump_sql_file&apos;</span>
<span class="hljs-keyword">GROUP</span> <span class="hljs-keyword">BY</span>
    TABLE_NAME,
    INDEX_NAME
<span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span>
    TABLE_NAME <span class="hljs-keyword">ASC</span>,
    INDEX_NAME <span class="hljs-keyword">ASC</span>
</code></pre>
<p>&#x4E00;&#x952E;&#x5BFC;&#x5165;&#x811A;&#x672C;</p>
<pre><code class="lang-shell">#!/bin/bash
##########
# 
# useage: ./mysql_to_pg.sh mysqldatabasename postgresqldatabasename
#
##########
mysqldb=$1
pgdb=$2
mysqltempname=.tmp.dump_sql_file.mysql
pgtempname=.tmp.dump_sql_file.pgsql
mysqldata=.tmp.mysqldata.sql
pgdata=.tmp.pgdata.sql

mysqldump --compatible=postgresql --default-character-set=utf8 -r $mysqltempname --add-drop-table -h ip_or_host -d ${mysqldb} -uroot  -pdbpassword

echo &quot;dump structure OK&quot;

python db_converter.py $mysqltempname $pgtempname

echo &quot;change structure OK&quot;


psql -f $pgtempname &quot;dbname=${pgdb} user=dbusername password=dbpassword&quot;

echo &quot;import structure OK&quot;

mysqldump -t ${mysqldb} --default-character-set=utf8 -h ip_or_host   -u root -pdbpassword &gt; ${mysqldata}

echo &quot;dump data OK&quot;

python db_converter.py ${mysqldata} ${pgdata}


echo &quot;change data OK&quot;

psql -f ${pgdata} &quot;dbname=${pgdb} user=dbusername password=dbpassword&quot;


echo &quot;import data OK&quot;

rm -f $mysqltempname $pgtempname ${mysqldata} ${pgdata}

echo &quot;remove tmp file OK&quot;
</code></pre>
<h2 id="pg&#x767B;&#x5F55;">pg&#x767B;&#x5F55;</h2>
<p>psql &quot;dbname=cbtest user=dbusername password=dbpassword&quot;</p>
<h2 id="&#x5BFC;&#x51FA;&#x9047;&#x5230;&#x95EE;&#x9898;">&#x5BFC;&#x51FA;&#x9047;&#x5230;&#x95EE;&#x9898;</h2>
<h1 id="&#x5C06;&#x6587;&#x4EF6;database-administrative-&#x4E0B;&#x5217;&#x4E2D;&#x7684;peer&#x6539;&#x4E3A;trust">&#x5C06;&#x6587;&#x4EF6;Database administrative &#x4E0B;&#x5217;&#x4E2D;&#x7684;peer&#x6539;&#x4E3A;trust</h1>
<p>$sudo nano /etc/postgresql/10/main/pg_hba.conf</p>
<h1 id="&#x91CD;&#x65B0;&#x52A0;&#x8F7D;&#x914D;&#x7F6E;">&#x91CD;&#x65B0;&#x52A0;&#x8F7D;&#x914D;&#x7F6E;</h1>
<p>$sudo /etc/init.d/portgresql reload</p>
<h1 id="peer&#x4E0D;&#x53EF;&#x4FE1;&#xFF0C;trust&#x53EF;&#x4FE1;&#xFF0C;md5&#x52A0;&#x5BC6;">peer(&#x4E0D;&#x53EF;&#x4FE1;)&#xFF0C;trust(&#x53EF;&#x4FE1;)&#xFF0C;md5(&#x52A0;&#x5BC6;)</h1>
<p> &#x2014;&#x2014;&#x2014;&#x2014;&#x2014;&#x2014;&#x2014;&#x2014;&#x2014;&#x2014;&#x2014;&#x2014;&#x2014;&#x2014;&#x2014;&#x2014; 
&#x7248;&#x6743;&#x58F0;&#x660E;&#xFF1A;&#x672C;&#x6587;&#x4E3A;CSDN&#x535A;&#x4E3B;&#x300C;Shannon-Li&#x300D;&#x7684;&#x539F;&#x521B;&#x6587;&#x7AE0;&#xFF0C;&#x9075;&#x5FAA;CC 4.0 by-sa&#x7248;&#x6743;&#x534F;&#x8BAE;&#xFF0C;&#x8F6C;&#x8F7D;&#x8BF7;&#x9644;&#x4E0A;&#x539F;&#x6587;&#x51FA;&#x5904;&#x94FE;&#x63A5;&#x53CA;&#x672C;&#x58F0;&#x660E;&#x3002;
&#x539F;&#x6587;&#x94FE;&#x63A5;&#xFF1A;<a href="https://blog.csdn.net/weixin_42555131/article/details/80893193" target="_blank">https://blog.csdn.net/weixin_42555131/article/details/80893193</a></p>
<p>&#x6539;&#x4E3A;&#x914D;&#x7F6E;&#x540E;&#x91CD;&#x65B0;&#x52A0;&#x8F7D;&#x914D;&#x7F6E;&#xFF0C;&#x53EF;&#x4EE5;&#x5BFC;&#x5165;&#x4E86;</p>
<h2 id="&#x91CD;&#x542F;pg">&#x91CD;&#x542F;pg</h2>
<p>sudo su - postgres  </p>
<p>pg_ctl reload -D /var/lib/pgsql/11/data/</p>
<h2 id="&#x9644;&#x4EF6;&#x811A;&#x672C;">&#x9644;&#x4EF6;&#x811A;&#x672C;</h2>
<h3 id="dbconverterpy">db_converter.py</h3>
<pre><code class="lang-python">
<span class="hljs-comment">#!/usr/bin/env python</span>
<span class="hljs-comment"># -*- coding: UTF-8 -*-</span>
<span class="hljs-string">&quot;&quot;&quot;
&#x52A0;&#x4E0A; # -*- coding: UTF-8 -*- &#x5C31;&#x652F;&#x6301;&#x4E2D;&#x6587;&#x6CE8;&#x91CA;
Fixes a MySQL dump made with the right format so it can be directly
imported to a new PostgreSQL database.
Dump using:
&#x8FD9;&#x91CC;&#x5BFC;&#x51FA;&#x4E86;&#x8868;&#x7ED3;&#x6784;&#x548C;&#x6570;&#x636E; &#x592A;&#x957F;&#x4E86;
mysqldump --compatible=postgresql --default-character-set=utf8 -r databasename.mysql -u root databasename -p

&#x8FD9;&#x91CC;&#x53EA;&#x5BFC;&#x51FA;&#x8868;&#x7ED3;&#x6784;
mysqldump --compatible=postgresql --default-character-set=utf8 -r databasename.mysql  -u root -p  -d databasename

&#x5BFC;&#x51FA;&#x6574;&#x4E2A;&#x6570;&#x636E;&#x5E93;&#x7ED3;&#x6784;&#x548C;&#x6570;&#x636E;
mysqldump -h localhost -uroot -p123456 database &gt; dump.sql

&#x5BFC;&#x51FA;&#x6574;&#x4E2A;&#x6570;&#x636E;&#x5E93;&#x7ED3;&#x6784;&#xFF08;&#x4E0D;&#x5305;&#x542B;&#x6570;&#x636E;&#xFF09;  -d
mysqldump -h localhost -uroot -p123456  -d database &gt; dump.sql
&quot;&quot;&quot;</span>

<span class="hljs-keyword">import</span> re
<span class="hljs-keyword">import</span> sys
<span class="hljs-keyword">import</span> os
<span class="hljs-keyword">import</span> time
<span class="hljs-keyword">import</span> subprocess


<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">parse</span><span class="hljs-params">(input_filename, output_filename,schema)</span>:</span>
    <span class="hljs-string">&quot;Feed it a file, and it&apos;ll output a fixed one&quot;</span>

    <span class="hljs-comment"># State storage</span>
    <span class="hljs-keyword">if</span> input_filename == <span class="hljs-string">&quot;-&quot;</span>:
        num_lines = <span class="hljs-number">-1</span>
    <span class="hljs-keyword">else</span>:
        num_lines = int(subprocess.check_output([<span class="hljs-string">&quot;wc&quot;</span>, <span class="hljs-string">&quot;-l&quot;</span>, input_filename]).strip().split()[<span class="hljs-number">0</span>])
    tables = {}
    current_table = <span class="hljs-keyword">None</span>
    creation_lines = []
    enum_types = []
    foreign_key_lines = []
    fulltext_key_lines = []
    sequence_lines = []
    cast_lines = []
    num_inserts = <span class="hljs-number">0</span>
    started = time.time()

    <span class="hljs-comment"># Open output file and write header. Logging file handle will be stdout</span>
    <span class="hljs-comment"># unless we&apos;re writing output to stdout, in which case NO PROGRESS FOR YOU.</span>
    <span class="hljs-keyword">if</span> output_filename == <span class="hljs-string">&quot;-&quot;</span>:
        output = sys.stdout
        logging = open(os.devnull, <span class="hljs-string">&quot;w&quot;</span>)
    <span class="hljs-keyword">else</span>:
        output = open(output_filename, <span class="hljs-string">&quot;w&quot;</span>)
        logging = sys.stdout

    <span class="hljs-keyword">if</span> input_filename == <span class="hljs-string">&quot;-&quot;</span>:
        input_fh = sys.stdin
    <span class="hljs-keyword">else</span>:
        input_fh = open(input_filename)


    output.write(<span class="hljs-string">&quot;-- Converted by db_converter\n&quot;</span>)
    output.write(<span class="hljs-string">&quot;START TRANSACTION;\n&quot;</span>)
    output.write(<span class="hljs-string">&quot;set search_path to %s;\n&quot;</span>%schema)
    output.write(<span class="hljs-string">&quot;SET standard_conforming_strings=off;\n&quot;</span>)
    output.write(<span class="hljs-string">&quot;SET escape_string_warning=off;\n&quot;</span>)
    output.write(<span class="hljs-string">&quot;SET CONSTRAINTS ALL DEFERRED;\n\n&quot;</span>)
    comment=<span class="hljs-keyword">False</span>
    <span class="hljs-keyword">for</span> i, line <span class="hljs-keyword">in</span> enumerate(input_fh):
        <span class="hljs-keyword">if</span> line.startswith(<span class="hljs-string">&quot;/*!50001&quot;</span>) <span class="hljs-keyword">and</span> (<span class="hljs-string">&quot;*/;&quot;</span> <span class="hljs-keyword">in</span> line):
            <span class="hljs-keyword">continue</span>
        <span class="hljs-keyword">if</span> line.startswith(<span class="hljs-string">&quot;SET @saved_cs_client&quot;</span>) <span class="hljs-keyword">or</span> line.startswith(<span class="hljs-string">&quot;SET character_set_client&quot;</span>):
            <span class="hljs-keyword">continue</span>
        <span class="hljs-keyword">if</span> comment <span class="hljs-keyword">and</span> <span class="hljs-string">&quot;ENGINE=MyISAM */;&quot;</span> <span class="hljs-keyword">in</span> line:
            comment=<span class="hljs-keyword">False</span>
            <span class="hljs-keyword">continue</span>
        <span class="hljs-keyword">if</span> line.startswith(<span class="hljs-string">&quot;/*!50001&quot;</span>) <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> (<span class="hljs-string">&quot;*/;&quot;</span> <span class="hljs-keyword">in</span> line):
            comment=<span class="hljs-keyword">True</span>
            <span class="hljs-keyword">continue</span>
        <span class="hljs-keyword">if</span> comment:
            <span class="hljs-keyword">continue</span>
        time_taken = time.time() - started
        percentage_done = (i+<span class="hljs-number">1</span>) / float(num_lines)
        secs_left = (time_taken / percentage_done) - time_taken
        logging.write(<span class="hljs-string">&quot;\rLine %i (of %s: %.2f%%) [%s tables] [%s inserts] [ETA: %i min %i sec]&quot;</span> % (
            i + <span class="hljs-number">1</span>,
            num_lines,
            ((i+<span class="hljs-number">1</span>)/float(num_lines))*<span class="hljs-number">100</span>,
            len(tables),
            num_inserts,
            secs_left // <span class="hljs-number">60</span>,
            secs_left % <span class="hljs-number">60</span>,
        ))
        logging.flush()
        line = line.decode(<span class="hljs-string">&quot;utf8&quot;</span>).strip().replace(<span class="hljs-string">r&quot;\\&quot;</span>, <span class="hljs-string">&quot;WUBWUBREALSLASHWUB&quot;</span>).replace(<span class="hljs-string">r&quot;\&apos;&quot;</span>, <span class="hljs-string">&quot;&apos;&apos;&quot;</span>).replace(<span class="hljs-string">&quot;WUBWUBREALSLASHWUB&quot;</span>, <span class="hljs-string">r&quot;\\&quot;</span>)
        <span class="hljs-comment"># Ignore comment lines</span>
        <span class="hljs-keyword">if</span> line.startswith(<span class="hljs-string">&quot;--&quot;</span>) <span class="hljs-keyword">or</span> line.startswith(<span class="hljs-string">&quot;/*&quot;</span>) <span class="hljs-keyword">or</span> line.startswith(<span class="hljs-string">&quot;LOCK TABLES&quot;</span>) <span class="hljs-keyword">or</span> line.startswith(<span class="hljs-string">&quot;UNLOCK TABLES&quot;</span>) <span class="hljs-keyword">or</span> <span class="hljs-keyword">not</span> line:
            <span class="hljs-keyword">continue</span>

        <span class="hljs-comment"># Outside of anything handling</span>
        <span class="hljs-keyword">if</span> current_table <span class="hljs-keyword">is</span> <span class="hljs-keyword">None</span>:
            <span class="hljs-comment"># Start of a table creation statement?</span>
            <span class="hljs-keyword">if</span> line.startswith(<span class="hljs-string">&quot;CREATE TABLE&quot;</span>):
                current_table = line.split(<span class="hljs-string">&apos;&quot;&apos;</span>)[<span class="hljs-number">1</span>]
                tables[current_table] = {<span class="hljs-string">&quot;columns&quot;</span>: []}
                creation_lines = []
            <span class="hljs-comment"># Inserting data into a table?</span>
            <span class="hljs-keyword">elif</span> line.startswith(<span class="hljs-string">&quot;DROP TABLE&quot;</span>):
                output.write(line.encode(<span class="hljs-string">&quot;utf8&quot;</span>).replace(<span class="hljs-string">&quot;\&quot;&quot;</span>,<span class="hljs-string">&quot;&quot;</span>) + <span class="hljs-string">&quot;\n&quot;</span>)
                num_inserts += <span class="hljs-number">1</span>
            <span class="hljs-keyword">elif</span> line.startswith(<span class="hljs-string">&quot;INSERT INTO&quot;</span>):
                line=line.replace(<span class="hljs-string">&quot;`&quot;</span>,<span class="hljs-string">&quot;&quot;</span>)
                output.write(line.encode(<span class="hljs-string">&quot;utf8&quot;</span>).replace(<span class="hljs-string">r&apos;\&quot;&apos;</span>,<span class="hljs-string">&apos;XWUBWUBREALSLASHWUB&apos;</span>).replace(<span class="hljs-string">r&apos;&quot;&apos;</span>,<span class="hljs-string">&apos;&apos;</span>).replace(<span class="hljs-string">&apos;XWUBWUBREALSLASHWUB&apos;</span>,<span class="hljs-string">r&apos;\&quot;&apos;</span>).replace(<span class="hljs-string">&quot;&apos;0000-00-00 00:00:00&apos;&quot;</span>, <span class="hljs-string">&quot;NULL&quot;</span>) + <span class="hljs-string">&quot;\n&quot;</span>)
                num_inserts += <span class="hljs-number">1</span>
            <span class="hljs-comment"># ???</span>
            <span class="hljs-keyword">else</span>:
                <span class="hljs-keyword">print</span> <span class="hljs-string">&quot;\n ! Unknown line in main body: %s&quot;</span> % line

        <span class="hljs-comment"># Inside-create-statement handling</span>
        <span class="hljs-keyword">else</span>:
            <span class="hljs-comment"># Is it a column?</span>
            <span class="hljs-keyword">if</span> line.startswith(<span class="hljs-string">&apos;&quot;&apos;</span>):
                useless, name, definition = line.strip(<span class="hljs-string">&quot;,&quot;</span>).split(<span class="hljs-string">&apos;&quot;&apos;</span>,<span class="hljs-number">2</span>)
                <span class="hljs-keyword">try</span>:
                    type, extra = definition.strip().split(<span class="hljs-string">&quot; &quot;</span>, <span class="hljs-number">1</span>)

                    <span class="hljs-comment"># This must be a tricky enum</span>
                    <span class="hljs-keyword">if</span> <span class="hljs-string">&apos;)&apos;</span> <span class="hljs-keyword">in</span> extra:
                        type, extra = definition.strip().split(<span class="hljs-string">&quot;)&quot;</span>)

                <span class="hljs-keyword">except</span> ValueError:
                    type = definition.strip()
                    extra = <span class="hljs-string">&quot;&quot;</span>
                extra = re.sub(<span class="hljs-string">&quot;CHARACTER SET [\w\d]+\s*&quot;</span>, <span class="hljs-string">&quot;&quot;</span>, extra.replace(<span class="hljs-string">&quot;unsigned&quot;</span>, <span class="hljs-string">&quot;&quot;</span>))
                extra = re.sub(<span class="hljs-string">&quot;COLLATE [\w\d]+\s*&quot;</span>, <span class="hljs-string">&quot;&quot;</span>, extra.replace(<span class="hljs-string">&quot;unsigned&quot;</span>, <span class="hljs-string">&quot;&quot;</span>))

                <span class="hljs-comment"># See if it needs type conversion</span>
                final_type = <span class="hljs-keyword">None</span>
                set_sequence = <span class="hljs-keyword">None</span>
                <span class="hljs-comment"># tinyint int bigint &#x90FD;&#x8F6C;&#x4E3A;bigint</span>
                <span class="hljs-keyword">if</span> type.startswith(<span class="hljs-string">&quot;tinyint(&quot;</span>):
                    <span class="hljs-comment"># type = &quot;int4&quot;</span>
                    type = <span class="hljs-string">&quot;bigint&quot;</span>
                    set_sequence = <span class="hljs-keyword">True</span>
                    final_type = <span class="hljs-string">&quot;boolean&quot;</span>
                <span class="hljs-keyword">elif</span> type.startswith(<span class="hljs-string">&quot;int(&quot;</span>):
                    <span class="hljs-comment"># type = &quot;integer&quot;</span>
                    type = <span class="hljs-string">&quot;bigint&quot;</span>
                    set_sequence = <span class="hljs-keyword">True</span>
                <span class="hljs-keyword">elif</span> type.startswith(<span class="hljs-string">&quot;bigint(&quot;</span>):
                    type = <span class="hljs-string">&quot;bigint&quot;</span>
                    set_sequence = <span class="hljs-keyword">True</span>
                <span class="hljs-keyword">elif</span> type == <span class="hljs-string">&quot;json&quot;</span>:
                    type = <span class="hljs-string">&quot;citext&quot;</span>
                <span class="hljs-keyword">elif</span> type == <span class="hljs-string">&quot;longtext&quot;</span>:
                    type = <span class="hljs-string">&quot;text&quot;</span>
                <span class="hljs-keyword">elif</span> type == <span class="hljs-string">&quot;mediumtext&quot;</span>:
                    type = <span class="hljs-string">&quot;text&quot;</span>
                <span class="hljs-keyword">elif</span> type == <span class="hljs-string">&quot;tinytext&quot;</span>:
                    type = <span class="hljs-string">&quot;text&quot;</span>
                <span class="hljs-keyword">elif</span> type.startswith(<span class="hljs-string">&quot;varchar(&quot;</span>):
                    size = int(type.split(<span class="hljs-string">&quot;(&quot;</span>)[<span class="hljs-number">1</span>].rstrip(<span class="hljs-string">&quot;)&quot;</span>))
                    <span class="hljs-comment">#type = &quot;varchar(%s)&quot; % (size * 2)</span>
                    type = <span class="hljs-string">&quot;citext&quot;</span>
                <span class="hljs-keyword">elif</span> type.startswith(<span class="hljs-string">&quot;smallint(&quot;</span>):
                    <span class="hljs-comment"># type = &quot;int2&quot;</span>
                    type = <span class="hljs-string">&quot;bigint&quot;</span>
                    set_sequence = <span class="hljs-keyword">True</span>
                <span class="hljs-keyword">elif</span> type == <span class="hljs-string">&quot;datetime&quot;</span>:
                    type = <span class="hljs-string">&quot;timestamp(0)&quot;</span>
                <span class="hljs-keyword">elif</span> type == <span class="hljs-string">&quot;double&quot;</span>:
                    type = <span class="hljs-string">&quot;double precision&quot;</span>
                <span class="hljs-keyword">elif</span> type.endswith(<span class="hljs-string">&quot;blob&quot;</span>):
                    type = <span class="hljs-string">&quot;bytea&quot;</span>
                <span class="hljs-keyword">elif</span> type.startswith(<span class="hljs-string">&quot;enum(&quot;</span>) <span class="hljs-keyword">or</span> type.startswith(<span class="hljs-string">&quot;set(&quot;</span>):
                    types_str = type.split(<span class="hljs-string">&quot;(&quot;</span>)[<span class="hljs-number">1</span>].rstrip(<span class="hljs-string">&quot;)&quot;</span>).rstrip(<span class="hljs-string">&apos;&quot;&apos;</span>)
                    types_arr = [type_str.strip(<span class="hljs-string">&apos;\&apos;&apos;</span>) <span class="hljs-keyword">for</span> type_str <span class="hljs-keyword">in</span> types_str.split(<span class="hljs-string">&quot;,&quot;</span>)]

                    <span class="hljs-comment"># Considered using values to make a name, but its dodgy</span>
                    <span class="hljs-comment"># enum_name = &apos;_&apos;.join(types_arr)</span>
                    enum_name = <span class="hljs-string">&quot;{0}_{1}&quot;</span>.format(current_table, name)

                    <span class="hljs-keyword">if</span> enum_name <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> enum_types:
                        output.write(<span class="hljs-string">&quot;CREATE TYPE {0} AS ENUM ({1}); \n&quot;</span>.format(enum_name, types_str));
                        enum_types.append(enum_name)
                    type = enum_name

                <span class="hljs-keyword">if</span> final_type:
                    cast_lines.append(<span class="hljs-string">&quot;ALTER TABLE \&quot;%s\&quot; ALTER COLUMN \&quot;%s\&quot; DROP DEFAULT, ALTER COLUMN \&quot;%s\&quot; TYPE %s USING CAST(\&quot;%s\&quot; as %s)&quot;</span> % (current_table, name, name, final_type, name, final_type))
                <span class="hljs-comment"># ID fields need sequences [if they are integers?]</span>
                <span class="hljs-keyword">if</span> name == <span class="hljs-string">&quot;id&quot;</span> <span class="hljs-keyword">and</span> set_sequence <span class="hljs-keyword">is</span> <span class="hljs-keyword">True</span>:
                    sequence_lines.append(<span class="hljs-string">&quot;CREATE SEQUENCE %s_id_seq&quot;</span> % (current_table))
                    sequence_lines.append(<span class="hljs-string">&quot;SELECT setval(&apos;%s_id_seq&apos;, max(id)) FROM %s&quot;</span> % (current_table, current_table))
                    sequence_lines.append(<span class="hljs-string">&quot;ALTER TABLE \&quot;%s\&quot; ALTER COLUMN \&quot;id\&quot; SET DEFAULT nextval(&apos;%s_id_seq&apos;)&quot;</span> % (current_table, current_table))
                <span class="hljs-comment"># Record it</span>
                creation_lines.append(<span class="hljs-string">&apos;&quot;%s&quot; %s %s&apos;</span> % (name, type, extra))
                tables[current_table][<span class="hljs-string">&apos;columns&apos;</span>].append((name, type, extra))
            <span class="hljs-comment"># Is it a constraint or something?</span>
            <span class="hljs-keyword">elif</span> line.startswith(<span class="hljs-string">&quot;PRIMARY KEY&quot;</span>):
                creation_lines.append(line.rstrip(<span class="hljs-string">&quot;,&quot;</span>))
            <span class="hljs-keyword">elif</span> line.startswith(<span class="hljs-string">&quot;CONSTRAINT&quot;</span>):
                foreign_key_lines.append(<span class="hljs-string">&quot;ALTER TABLE \&quot;%s\&quot; ADD CONSTRAINT %s DEFERRABLE INITIALLY DEFERRED&quot;</span> % (current_table, line.split(<span class="hljs-string">&quot;CONSTRAINT&quot;</span>)[<span class="hljs-number">1</span>].strip().rstrip(<span class="hljs-string">&quot;,&quot;</span>)))
                foreign_key_lines.append(<span class="hljs-string">&quot;CREATE INDEX ON \&quot;%s\&quot; %s&quot;</span> % (current_table, line.split(<span class="hljs-string">&quot;FOREIGN KEY&quot;</span>)[<span class="hljs-number">1</span>].split(<span class="hljs-string">&quot;REFERENCES&quot;</span>)[<span class="hljs-number">0</span>].strip().rstrip(<span class="hljs-string">&quot;,&quot;</span>)))
            <span class="hljs-keyword">elif</span> line.startswith(<span class="hljs-string">&quot;UNIQUE KEY&quot;</span>):
                creation_lines.append(<span class="hljs-string">&quot;UNIQUE (%s)&quot;</span> % line.split(<span class="hljs-string">&quot;(&quot;</span>)[<span class="hljs-number">1</span>].split(<span class="hljs-string">&quot;)&quot;</span>)[<span class="hljs-number">0</span>])
            <span class="hljs-keyword">elif</span> line.startswith(<span class="hljs-string">&quot;FULLTEXT KEY&quot;</span>):

                fulltext_keys = <span class="hljs-string">&quot; || &apos; &apos; || &quot;</span>.join( line.split(<span class="hljs-string">&apos;(&apos;</span>)[<span class="hljs-number">-1</span>].split(<span class="hljs-string">&apos;)&apos;</span>)[<span class="hljs-number">0</span>].replace(<span class="hljs-string">&apos;&quot;&apos;</span>, <span class="hljs-string">&apos;&apos;</span>).split(<span class="hljs-string">&apos;,&apos;</span>) )
                fulltext_key_lines.append(<span class="hljs-string">&quot;CREATE INDEX ON %s USING gin(to_tsvector(&apos;english&apos;, %s))&quot;</span> % (current_table, fulltext_keys))

            <span class="hljs-keyword">elif</span> line.startswith(<span class="hljs-string">&quot;KEY&quot;</span>):
                <span class="hljs-keyword">pass</span>
            <span class="hljs-comment"># Is it the end of the table?</span>
            <span class="hljs-keyword">elif</span> line == <span class="hljs-string">&quot;);&quot;</span>:
                <span class="hljs-comment"># output.write(&quot;CREATE TABLE \&quot;%s\&quot; (\n&quot; % current_table)</span>
                output.write(<span class="hljs-string">&quot;CREATE TABLE %s (\n&quot;</span> % current_table)
                <span class="hljs-keyword">for</span> i, line <span class="hljs-keyword">in</span> enumerate(creation_lines):
                    <span class="hljs-comment"># &#x53BB;&#x9664;&#x5B57;&#x6BB5;&#x7684;&#x53CC;&#x5F15;&#x53F7;</span>
                    line = line.replace(<span class="hljs-string">&quot;\&quot;&quot;</span>, <span class="hljs-string">&quot;&quot;</span>)
                    output.write(<span class="hljs-string">&quot;    %s%s\n&quot;</span> % (line, <span class="hljs-string">&quot;,&quot;</span> <span class="hljs-keyword">if</span> i != (len(creation_lines) - <span class="hljs-number">1</span>) <span class="hljs-keyword">else</span> <span class="hljs-string">&quot;&quot;</span>))
                output.write(<span class="hljs-string">&apos;);\n\n&apos;</span>)
                current_table = <span class="hljs-keyword">None</span>
            <span class="hljs-comment"># ???</span>
            <span class="hljs-keyword">else</span>:
                <span class="hljs-keyword">print</span> <span class="hljs-string">&quot;\n ! Unknown line inside table creation: %s&quot;</span> % line


    <span class="hljs-comment"># Finish file</span>
    output.write(<span class="hljs-string">&quot;\n-- Post-data save --\n&quot;</span>)
    output.write(<span class="hljs-string">&quot;COMMIT;\n&quot;</span>)
    output.write(<span class="hljs-string">&quot;START TRANSACTION;\n&quot;</span>)

    <span class="hljs-comment"># Write typecasts out</span>
    output.write(<span class="hljs-string">&quot;\n-- Typecasts --\n&quot;</span>)
    <span class="hljs-keyword">for</span> line <span class="hljs-keyword">in</span> cast_lines:
        output.write(<span class="hljs-string">&quot;%s;\n&quot;</span> % line)

    <span class="hljs-comment"># Write FK constraints out</span>
    output.write(<span class="hljs-string">&quot;\n-- Foreign keys --\n&quot;</span>)
    <span class="hljs-keyword">for</span> line <span class="hljs-keyword">in</span> foreign_key_lines:
        output.write(<span class="hljs-string">&quot;%s;\n&quot;</span> % line)

    <span class="hljs-comment"># Write sequences out</span>
    output.write(<span class="hljs-string">&quot;\n-- Sequences --\n&quot;</span>)
    <span class="hljs-keyword">for</span> line <span class="hljs-keyword">in</span> sequence_lines:
        output.write(<span class="hljs-string">&quot;%s;\n&quot;</span> % line)

    <span class="hljs-comment"># Write full-text indexkeyses out</span>
    output.write(<span class="hljs-string">&quot;\n-- Full Text keys --\n&quot;</span>)
    <span class="hljs-keyword">for</span> line <span class="hljs-keyword">in</span> fulltext_key_lines:
        output.write(<span class="hljs-string">&quot;%s;\n&quot;</span> % line)

    <span class="hljs-comment"># Finish file</span>
    output.write(<span class="hljs-string">&quot;\n&quot;</span>)
    output.write(<span class="hljs-string">&quot;COMMIT;\n&quot;</span>)
    <span class="hljs-keyword">print</span> <span class="hljs-string">&quot;&quot;</span>


<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&quot;__main__&quot;</span>:
    parse(sys.argv[<span class="hljs-number">1</span>], sys.argv[<span class="hljs-number">2</span>], sys.argv[<span class="hljs-number">3</span>])
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="2019-12-28-Postgres学习笔记.html" class="navigation navigation-prev " aria-label="Previous page: 2.2019-12-28-Postgres学习笔记">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="2020-01-04-docker-PostgreSQL安装文档.html" class="navigation navigation-next " aria-label="Next page: 4.2020-01-04-docker-PostgreSQL安装文档">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"layout":"post","title":"3.2019-12-28-脚本MYSQL导出数据到PG","categories":["SQL","PostgreSQL","MYSQL"],"description":"脚本MYSQL导出数据到PG","keywords":"SQL, Postgres,PostgreSQL","level":"2.20.3","depth":2,"next":{"title":"4.2020-01-04-docker-PostgreSQL安装文档","level":"2.20.4","depth":2,"path":"PostgreSQL/2020-01-04-docker-PostgreSQL安装文档.md","ref":"PostgreSQL/2020-01-04-docker-PostgreSQL安装文档.md","articles":[]},"previous":{"title":"2.2019-12-28-Postgres学习笔记","level":"2.20.2","depth":2,"path":"PostgreSQL/2019-12-28-Postgres学习笔记.md","ref":"PostgreSQL/2019-12-28-Postgres学习笔记.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"PostgreSQL/2019-12-28-脚本MYSQL导出数据到PG.md","mtime":"2019-12-30T06:46:25.036Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-08-27T08:51:05.639Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

